//
//  UFViewUtil.h
//  UniversalFramework
//
//  Created by 谢朋 on 2016/11/2.
//  Copyright © 2017年 北京华星成汇文化发展有限公司. All rights reserved.
//

@import UIKit;

@class UFExpression;

// 屏幕方向枚举
typedef enum {
    UFScreenOrientationPortrait = 0, // 竖向
    UFScreenOrientationLandscape // 横向
} UFScreenOrientation;

// 视图工具类
@interface UFViewUtil : NSObject

#pragma mark - 颜色
// 通过十六位RGB值获取UIColor对象
+ (UIColor *)colorByRgbHex:(NSString *)rgbHex;
+ (UIColor *)colorByRgbHex:(NSString *)rgbHex alpha:(float)alpha;

#pragma mark - 屏幕方向
// 通过界面方向获取屏幕方向
+ (UFScreenOrientation)screenOrientation:(UIInterfaceOrientation)interfaceOrientation;

// 通过屏幕方向获取屏幕尺寸
+ (CGSize)screenSize:(UFScreenOrientation)screenOrientation;

// 通过应用宽度获取屏幕方向
+ (UFScreenOrientation)screenOrientationByWidth:(CGFloat)screenWidth;

#pragma mark - 布局
// 添加顶部相对约束
+ (void)addConstraintWithItem:(UIView *)view1 toItem:(UIView *)view2 relativeTop:(CGFloat)top;
// 添加底部相对约束
+ (void)addConstraintWithItem:(UIView *)view1 toItem:(UIView *)view2 relativeBottom:(CGFloat)bottom;
// 添加左边相对约束
+ (void)addConstraintWithItem:(UIView *)view1 toItem:(UIView *)view2 relativeLeft:(CGFloat)left;
// 添加右边相对约束
+ (void)addConstraintWithItem:(UIView *)view1 toItem:(UIView *)view2 relativeRight:(CGFloat)right;
// 添加中心X轴坐标相对约束
+ (void)addConstraintWithItem:(UIView *)view1 toItem:(UIView *)view2 relativeCenterX:(CGFloat)centerX;
// 添加中心Y轴坐标相对约束
+ (void)addConstraintWithItem:(UIView *)view1 toItem:(UIView *)view2 relativeCenterY:(CGFloat)centerY;

// 添加顶部相对底部约束
+ (void)addConstraintWithItem:(UIView *)view1 toItem:(UIView *)view2 relativeTopToBottom:(CGFloat)topToBottom;
// 添加底部相对顶部约束
+ (void)addConstraintWithItem:(UIView *)view1 toItem:(UIView *)view2 relativeBottomToTop:(CGFloat)bottomToTop;
// 添加左边相对右边约束
+ (void)addConstraintWithItem:(UIView *)view1 toItem:(UIView *)view2 relativeLeftToRight:(CGFloat)leftToRight;
// 添加右边相对左边约束
+ (void)addConstraintWithItem:(UIView *)view1 toItem:(UIView *)view2 relativeRightToLeft:(CGFloat)rightToLeft;

// 添加左上约束
+ (void)addConstraintWithItem:(UIView *)view relativeTop:(CGFloat)top relativeLeft:(CGFloat)left;
// 添加左下约束
+ (void)addConstraintWithItem:(UIView *)view relativeBottom:(CGFloat)bottom relativeLeft:(CGFloat)left;
// 添加右上约束
+ (void)addConstraintWithItem:(UIView *)view relativeTop:(CGFloat)top relativeRight:(CGFloat)right;
// 添加右下约束
+ (void)addConstraintWithItem:(UIView *)view relativeBottom:(CGFloat)bottom relativeRight:(CGFloat)right;
// 添加中心约束
+ (void)addConstraintWithItem:(UIView *)view relativeCenterX:(CGFloat)centerX relativeCenterY:(CGFloat)centerY;

// 添加宽相对约束
+ (void)addConstraintWithItem:(UIView *)view1 toItem:(UIView *)view2 relativeWidth:(CGFloat)width;
// 添加高相对约束
+ (void)addConstraintWithItem:(UIView *)view1 toItem:(UIView *)view2 relativeHeight:(CGFloat)height;
// 添加宽绝对约束
+ (void)addConstraintWithItem:(UIView *)view1 absoluteWidth:(CGFloat)width;
// 添加高绝对约束
+ (void)addConstraintWithItem:(UIView *)view1 absoluteHeight:(CGFloat)height;
// 添加宽高约束
+ (void)addConstraintWithItem:(UIView *)view relativeWidth:(CGFloat)width relativeHeight:(CGFloat)height;
+ (void)addConstraintWithItem:(UIView *)view absoluteWidth:(CGFloat)width relativeHeight:(CGFloat)height;
+ (void)addConstraintWithItem:(UIView *)view relativeWidth:(CGFloat)width absoluteHeight:(CGFloat)height;
+ (void)addConstraintWithItem:(UIView *)view absoluteWidth:(CGFloat)width absoluteHeight:(CGFloat)height;

// 修改宽绝对约束
+ (void)modifyConstraintWithItem:(UIView *)view1 absoluteWidth:(CGFloat)width;
// 修改高绝对约束
+ (void)modifyConstraintWithItem:(UIView *)view1 absoluteHeight:(CGFloat)height;

// 删除视图的所有约束，包含父视图和本视图
+ (void)removeAllContraintWithItem:(UIView *)view;

#pragma mark - 其它
// 显示短Toast
+ (void)showShortToast:(NSString *)message;

// 创建表达式
+ (UFExpression *)expressionWithResult:(BOOL)result warning:(NSString *)warning;

// 验证表达式
+ (BOOL)validateExpressions:(NSArray<UFExpression *> *)expressions;

@end

// 表达式
@interface UFExpression : NSObject

@property (assign, nonatomic, readonly) BOOL result; // 结果
@property (strong, nonatomic, readonly) NSString *warning; // 警告

// 通过结果、警告初始化
- (instancetype)initWithResult:(BOOL)result warning:(NSString *)warning;

@end
